package top.ffhome.concurrent.beautiful.ch01;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class SleepTest2 {
    private static final Log log = LogFactory.get();
    private static final Lock lock = new ReentrantLock();

    public static void main(String[] args) throws InterruptedException {
        Thread threadA = new Thread(() -> {
            lock.lock();
            try {
                log.info("child threadA is in sleep");
                Thread.sleep(10000);
                log.info("child threadA is in awaked");
            } catch (InterruptedException e) {
                log.error(e);
            } finally {
                lock.unlock();
            }
        });

        Thread threadB = new Thread(() -> {
            lock.lock();
            try {
                log.info("child threadB is in sleep");
                Thread.sleep(10000);
                log.info("child threadB is in awaked");
            } catch (InterruptedException e) {
                log.error(e);
            } finally {
                lock.unlock();
            }
        });

        threadA.start();
        threadB.start();
    }
}
